{% extends "base.html" %}
{% block content -%}
{% if myfeeds -%}
<fieldset id="ownfeeds">
    <legend>{{_("Custom Rss")}}</legend>
    {% for feed in myfeeds -%}
    <div class="book">
        <div class="titleRow">{{feed.title}} {% if feed.isfulltext %}
            <img alt="{{_("Fulltext")}}" src="static/fulltext.gif" border="0" />{% endif %}
        </div>
        <div class="cornerControls">
            <a href="/delfeed/{{feed.key().id()}}" class="actionButton">{{_("Delete")}}</a>
        </div>
        <div class="summaryRow">
            <a href="{{feed.url}}" target="_blank" style="text-decoration:none;color:grey;" 
                {%if feed.url|length>80%}title="{{feed.url}}"{%endif%}>
            {%if feed.url|length>80%}{{feed.url[:80]}}...{%else%}{{feed.url}}{%endif%}</a>
        </div>
    </div>
    {% endfor -%}
    <form class="pure-form" action="" method="POST">
    <div class="book" style="border-bottom:0;">
        <div class="titleRow">
            <input type="text" name="t" placeholder={{_("Title")}} style="width:250px;" />
            <input type="checkbox" name="fulltext" id="fulltext" />
            <img alt="{{_("Fulltext")}}" src="static/fulltext.gif" border="0" onclick="toggleFulltext();" />
        </div>
        <div class="summaryRow">
            <input type="text" name="url" style="width:600px;margin-top:8px;" placeholder="URL" />
        </div>
        <input type="submit" value="{{_("Add")}}" class="pure-button pure-button-primary" style="margin-top:8px;" />
        {% if tips %}<p style="color:red;font-size:0.7em;">{{tips}}</p>{% endif %}
    </div>
    </form>
</fieldset>
{% endif -%}
<fieldset id="mybooks" style="margin-top:10px;">
    <legend>{{_("Subscribed")}}</legend>
    {% for book in books -%}
    {% if nickname in book.users -%}
    <div class="book">
        <div class="titleRow">{{book.title}}
        {% if book.separate -%}
          <img alt="{{_("Separate")}}" src="static/separate.gif" border="0" />
        {% endif -%}
        </div>
        <div class="cornerControls">
          {% if book.needs_subscription -%}
            <a href="/booklogininfo/{{book.key().id()}}" class="actionButton"
            {% if not user.subscription_info(book.title) %}style="color:red;"{% endif %}
            >{{_("Login Info")}}</a>
          {% endif -%}
            <a href="/unsubscribe/{{book.key().id()}}" class="actionButton">{{_("Unsubscribe")}}</a>
        </div>
        <div class="summaryRow">
            {%if book.description|length>80%}{{book.description[:80]}}...<span>{{book.description}}</span>{%else%}{{book.description}}{%endif%}
        </div>
    </div>
    {% endif -%}
    {% endfor -%}
</fieldset>
<fieldset id="books" style="margin-top:10px;">
    <legend>{{_("Unsubscribed")}}</legend>
    {% for book in books -%}
    {% if nickname not in book.users -%}
    <div class="book">
        <div class="titleRow">{{book.title}}
            <input type="checkbox" id="separate_{{book.key().id()}}" style="margin-left:1em;" />
            <img alt="{{_("Separate")}}" src="static/separate.gif" border="0" onclick="toggleSeparate('{{book.key().id()}}');" />
        </div>
        <div class="cornerControls">
            <!--<a href="/subscribe/{{book.key().id()}}" class="actionButton">{{_("Subscribe")}}</a>-->
            <a href="javascript:void(0)" onclick="doSubscribe('{{book.key().id()}}')" class="actionButton">{{_("Subscribe")}}</a>
        </div>
        <div class="summaryRow">
            {%if book.description|length>80%}{{book.description[:80]}}...<span>{{book.description}}</span>{%else%}{{book.description}}{%endif%}
        </div>
    </div>
    {% endif -%}
    {% endfor -%}
</fieldset>
{% endblock -%}
{% block js -%}
<script type="text/javascript">
function toggleFulltext() {
  var btnft = document.getElementById("fulltext");
  btnft.checked = !btnft.checked;
}
function toggleSeparate(id) {
  id = "separate_" + id
  var btnft = document.getElementById(id);
  btnft.checked = !btnft.checked;
}

function doSubscribe(id) {
  var btnSeparate = document.getElementById("separate_" + id);
  target = "/subscribe/" + id
  if (btnSeparate.checked)
    target += "?separate=true"
  window.location.href = target
}
</script>
{% endblock -%}